<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>经济管理学院</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href='css/style.css' type="text/css">


</head>
<style>

    body {
        background-color: #660099
    }

    a:visited {
        color: gray;
    }
</style>

<script type='text/javascript' src='js/prototype.js'></script>
<script type='text/javascript' src='js/sha1.js'></script>
<script type='text/javascript' src='js/public.js'></script>
<script type="text/javascript">
    var code;
    var start;
    var stop;
    var shake;
    var grade = " ";
    var userenteryear;
    var userEnterYear1;
    var userEnterYear2;
    var userEnterYear3;
    var userEnterYear4;
    var major;
    var request = {
        QueryString: function (val) {
            var uri = window.location.search;
            var re = new RegExp("" + val + "=([^&?]*)", "ig");
            return ((uri.match(re)) ? (uri.match(re)[0]
                    .substr(val.length + 1)) : null);
        }
    };
    function showuserkey() {
        online();
    }
    function outline() {
        var params = "";
        new Ajax.Request("json/logout", {
            method: "post",
            parameters: params,
            onComplete: function (request) {
                var res = request.responseText.evalJSON();
                window.location.href = "login-new.html";
            },
            asynchronous: true
        });
    }
    function online() {
        viewLecturesOutline();
        status();
        createCode();
    }
    function viewLecturesOutline() {
        var lectureId = request.QueryString("lectureId");
        var params = "lectureId=" + encodeURIComponent(lectureId);
        new Ajax.Request(
                "json/viewLecturesOutline",
                {
                    method: "post",
                    parameters: params,
                    onComplete: function (request) {
                        var res = request.responseText.evalJSON();
                        if (res["result"]["flag"] == "true") {
                            if (res["result"]["userEnterYear1"] !== null)
                                grade += res["result"]["userEnterYear1"] + " ";
                            if (res["result"]["userEnterYear2"] !== null)
                                grade += res["result"]["userEnterYear2"] + " ";
                            if (res["result"]["userEnterYear3"] !== null)
                                grade += res["result"]["userEnterYear3"] + " ";
                            if (res["result"]["userEnterYear4"] !== null)
                                grade += res["result"]["userEnterYear4"] + " ";
                            start = compareTime(res["result"]["startTime"]);
                            stop = compareTime(res["result"]["stopTime"]);
                            userEnterYear1 = res["result"]["userEnterYear1"];
                            userEnterYear2 = res["result"]["userEnterYear2"];
                            userEnterYear3 = res["result"]["userEnterYear3"];
                            userEnterYear4 = res["result"]["userEnterYear4"];

                            var str = res["result"]["lecYear"];
                            var lecyear1 = str.substr(0, 4);
                            str = str.replace(lecyear1, '');
                            var lecyear2 = str.substr(0, 4);
                            str = str.replace(lecyear2, '');
                            var lecterm = str.substr(0, 1);
                            shake = res["result"]["shake"];
                            var tmp = "<ul style='width:100%; border-bottom:1px  #999 dotted;'><li style='margin-left:20px;margin-top:20px;'>学期：" + lecyear1 + "——" + lecyear2 + "学年 第" + lecterm + "学期</li><li style='margin-left:20px; '>主题："
                                    + res["result"]["lecName"]
                                    + " </li><li style='margin-left:20px;'>主讲人：" + res["result"]["lecSpeaker"]
                                    + "</li><li style='margin-left:20px;'>举办时间：" + res["result"]["lecTime"]
                                    + "</li><li style='margin-left:20px;'>举办地点：" + res["result"]["lecPlace"]
                                    + "</li><li style='margin-left:20px;''>参与年级：" + grade
                                    + "</li><li style='margin-left:20px;'>报名开始时间：" + res["result"]["startTime"]
                                    + "</li><li style='margin-left:20px;'>报名截止时间：" + res["result"]["stopTime"]
                                    + "</li><li style='margin-left:20px;'>发放票数：" + res["result"]["lecCodeNumber"]
                                    + "</li><li style='margin-left:20px;''>备注：" + res["result"]["lecNote"]
                                    + "</li><li style='margin-left:20px;'></ul>";
                            $("iteratorProductsTarget").innerHTML += tmp;
                        }
                    },
                    asynchronous: false
                });
    }


    function RegisterLecture() {
        var lectureId = request.QueryString("lectureId");
        var params = "lectureId=" + lectureId;
        if (start == "大于") {
            alert("请到报名时间之后再报名！");

        }
        else if (stop == "小于") {
            alert("报名已经截止");
        }
        else if (userEnterYear1 == userenteryear || userEnterYear2 == userenteryear || userEnterYear3 == userenteryear || userEnterYear4 == userenteryear || major == "梁希") {

            new Ajax.Request("json/registerOneLecture", {
                method: "post",
                parameters: params,
                onComplete: function (request) {
                    var res = request.responseText.evalJSON();

                    if (res["result"]["flag"] == "true") {
                        alert("你已成功报名");
                        window.location.href = "StuOperateLecture.html?lectureId="
                                + lectureId;
                    }
                },
                asynchronous: false
            });
        }
        else {
            alert("该活动适合" + grade + "级学生参加");
        }
    }

    function createCode() {
        code = "";
        var codeLength = 4;
        var checkCode = document.getElementById("htmlcode2");
        var selectChar = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');//所有候选组成验证码的字符，当然也可以用中文的

        for (var i = 0; i < codeLength; i++) {

            var charIndex = Math.floor(Math.random() * 36);
            code += selectChar[charIndex];

        }

        if (checkCode) {

            checkCode.value = code;

        }

    }


    function status() {
        var lectureId = request.QueryString("lectureId");
        var params = "lectureId=" + encodeURIComponent(lectureId);
        new Ajax.Request("json/userLectureStatus", {
            method: "post",
            parameters: params,
            onComplete: function (request) {
                var res = request.responseText.evalJSON();

                var codestatus = res["result"]["status"];
                var order = res["result"]["order"];
                if (codestatus == "check") {
                    var reshtml = "<li style='float: left; width: 180px;font-size: 20px; color: red;'>已报名</li><li style='float: left; width: 280px;font-size: 20px; color: red;'>领票序号：" + order + "</li>"
                    $("registerstatus").innerHTML += reshtml;
                    document.getElementById("checkstatustext").innerHTML = "已签到";
                    document.getElementById("checkshow1").innerHTML = " ";
                    document.getElementById("checkshow2").innerHTML = " ";
                    document.getElementById("checkshow3").innerHTML = " ";

                }
                else if (codestatus == "shake") {
                    var reshtml = "<li style='float: left; width: 180px;font-size: 20px; color: red;'>已报名</li><li style='float: left; width: 280px;font-size: 20px; color: red;'>领票序号：" + order + "</li>"
                    $("registerstatus").innerHTML += reshtml;
                    document.getElementById("checkstatustext").innerHTML = "请领取签到码后及时签到";
                    alert('如果发现验证码不能用，请注意小写L、大写i和数字1的区别，如果不能区分请联系团委老师，下一次经管讲坛将不使用易混淆的字母作为签到码');
                }
                else if (codestatus == "noshake" & shake == "1") {
                    var reshtml = "<li style='float: left; width: 180px;font-size: 20px; color: red;'>已报名</li><li style='float: left; width: 300px;font-size: 20px; color: red;'>未被系统选中，请下次继续报名</li>"
                    $("registerstatus").innerHTML += reshtml;
                    document.getElementById("checkstatustext").innerHTML = "未签到";
                    document.getElementById("checkshow1").innerHTML = " ";
                    document.getElementById("checkshow2").innerHTML = " ";
                    document.getElementById("checkshow3").innerHTML = " ";
                }
                else if (codestatus == "noshake" & shake == "0") {
                    var reshtml = "<li style='float: left; width: 180px;font-size: 20px; color: red;'>已报名<input type='button' value='取消报名' onclick='deleteRegisterLecture()'></li><li style='float: left; width: 300px;font-size: 20px; color: red;'>请在报名截止后查看系统分配结果</li>"
                    $("registerstatus").innerHTML += reshtml;
                    document.getElementById("checkstatustext").innerHTML = "未签到";
                    document.getElementById("checkshow1").innerHTML = " ";
                    document.getElementById("checkshow2").innerHTML = " ";
                    document.getElementById("checkshow3").innerHTML = " ";

                }
                else if (codestatus == "noregister") {
                    var reshtml = "<li style='float: left; width: 220px;font-size: 20px; color: red;' >未报名<input type='button' value='报名' onclick='RegisterLecture()'></li>"
                    $("registerstatus").innerHTML += reshtml;
                    document.getElementById("checkstatustext").innerHTML = "请先报名";
                    document.getElementById("checkshow1").innerHTML = " ";
                    document.getElementById("checkshow2").innerHTML = " ";
                    document.getElementById("checkshow3").innerHTML = " ";
                }

            },
            asynchronous: false
        });
    }
    function check() {
        var inputCode = document.getElementById("htmlcode1").value;
        var lectureId = request.QueryString("lectureId");
        var checkcode = document.getElementById("checkcode").value;
        if (checkcode == "" || inputCode == "") {
            alert("请输入签到码和验证码！");
            createCode();
        }
        else if (inputCode != code) {
            alert("验证码输入错误！");
            createCode();
        }
        else {
            var params = "lectureId=" + encodeURIComponent(lectureId) + "&lecture_registerCode="
                    + encodeURIComponent(checkcode);

            new Ajax.Request("json/checkLectureWithCode", {
                method: "post",
                parameters: params,
                onComplete: function (request) {
                    var res = request.responseText.evalJSON();

                    if (res["result"]["flag"] == "true") {
                        alert("成功签到");
                        window.location.href = "StuOperateLecture.html?lectureId="
                                + lectureId;
                    } else {
                        alert("签到码错误或已被使用！");
                    }
                },
                asynchronous: false
            });
        }
    }
    function deleteRegisterLecture() {
        var lectureId = request.QueryString("lectureId");
        var params = "lectureId=" + encodeURIComponent(lectureId);
        if (confirm("确定取消报名？")) {
            new Ajax.Request("json/studentDeleteUser_registerLecture", {
                method: "post",
                parameters: params,
                onComplete: function (request) {
                    var res = request.responseText.evalJSON();
                    if (res["result"]["flag"] == "true") {
                        alert("已取消报名");
                        window.location.href = "StuOperateLecture.html?lectureId="
                                + lectureId;
                    } else {
                        alert("请在系统分配前取消");
                    }
                },
                asynchronous: false
            });
        }
    }
</script>
<body onload="showuserkey()">
<div class="container">
    <div class="row">
        <div class="col-xs-12" style="text-align:center;color:white;font-size:18px;border-bottom:4px solid #660033">
            经管院学术讲坛事务系统
        </div>
    </div>
    <div class="row" style="margin-bottom:10px;">
        <!--div class="col-lg-2 col-md-2 col-sm-2 col-xs-1"></div-->
        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-6" id="username" style="color:white;float:left;">&nbsp;你好</div>
        <div class="col-lg-5 col-md-5 col-sm-5 col-xs-6"><a href="editorUser.html" target="_blank"
                                                            style="text-decoration: none;float:right;">修改密码</a></div>

    </div>
</div>

<div id="main" class="container">

    <div style="width: 100%; font-size: 22px;">
        <div style="margin-top: 50px;height: 500px">
            <div>
                <table width=100% border="0" margin-left="0"
                       style="font-size: 14px; border: 2px solid #999;">
                    <tr>
                        <td style="border-bottom: 1px #999 dotted;" id="registerstatus">
                            <li
                                    style="float: left; width: 120px; font-size: 20px; color: red;">报名状态：
                            </li>
                            <li style="float: right; margin-right:20%;"><a href="StudentIndex.html">返回首页</a></li>

                        </td>
                    </tr>
                    <tr>
                        <td id="checkstatus" style="border-bottom: 1px #999 dotted;"><p
                                style="font-size: 20px; color: red;">签到状态：</p>
                            <li id="checkstatustext"
                                style="width: 300px; color: red; font-size: 20px"></li>
                            <li id="checkshow1"><font color="white">签到码：</font><input id="checkcode" type="text"
                                                                                      value="" style="width:20%;"></li>
                            <li id="checkshow2"><font color="white">验证码：</font><input id="htmlcode1" type="text"
                                                                                      value="" style="width:20%;"><input
                                    id="htmlcode2" style="width: 60px; background: gray; border: 0;"
                                    onClick="createCode()" readonly="readonly"/> <a href="#"
                                                                                    onClick="createCode()">看不清楚</a></li>
                            <li id="checkshow3"><input type="button" value="签到"
                                                       onclick="check()"></li>
                        </td>
                    </tr>
                    <tr>
                        <td style="font-size: 16px;">
                            <div id="iteratorProductsTarget" style="color:white;">

                            </div>
                        </td>
                    </tr>
                </table>
            </div>

        </div>

    </div>

</div>

</body>
</html>
